package com.example.home.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.alibaba.android.arouter.launcher.ARouter
import com.example.common.ARouterPath
import com.example.home.entity.SimpleTypeEntity
import com.example.home.ui.TypeJumpFragment

class HomePageAdapter(private val types:List<SimpleTypeEntity>, private val manager: FragmentManager):FragmentStatePagerAdapter(manager) {
    private val fragments:MutableList<Fragment> = mutableListOf()
    init {
        for (entity in types){
            val fragment=TypeJumpFragment()
            fragments.add(fragment)
        }
    }

    override fun getCount(): Int=fragments.size


    override fun getItem(position: Int): Fragment=ARouter.getInstance()
        .build(ARouterPath.PAGE_JUMP).withString("id",types[position].channelid)
        .navigation() as Fragment

    override fun getPageTitle(position: Int): CharSequence=types[position].typename

    override fun getItemPosition(`object`:Any):Int=PagerAdapter.POSITION_NONE

}